<template>
  <div>
    <input type="text" /><button @click="search_pro">搜索</button>
    <hr />
    <van-radio-group v-model="checked">
      <van-radio
        v-for="(item, index) in pro_arr.list"
        :key="index"
        :name="item.id"
        >{{ item.name }}</van-radio
      >
    </van-radio-group>
    <button @click="confirm_pro">确定</button>
  </div>
</template>

<script>
import apis from "../utils/api_nots";
import { onMounted, reactive, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
export default {
  setup() {
    let pro_arr = reactive({
      list: [],
    });
    const checked = ref("0");
    const router = useRouter();
    onMounted(() => {
      apis
        .get_pros({
          size: 20,
          page: 1,
          state: 1,
          wx_xcx_status: 1,
        })
        .then((res) => {
          let newArr = res.data.data.data;
          pro_arr.list = newArr;
        });
    });
    function search_pro() {}
    // 选择产品之后确定
    function confirm_pro() {
      console.log(pro_arr.list, checked.value);
      const pro_infor = pro_arr.list.filter((item) => {
        return item.id == checked.value;
      });
      console.log(pro_infor);
      // 将class_id存放，用来获取合同信息
      localStorage.setItem("contract_infor",JSON.stringify({
          "class_id":pro_infor[0].class_id,
          "name":pro_infor[0].name,
          "product_time":pro_infor[0].product_time,
          "rate":pro_infor[0].rate+"%",
          "money":pro_infor[0].money
      }));
      router.push({
        path: "/personal_sign",
      });
    }
    return {
      checked,
      search_pro,
      pro_arr,
      confirm_pro,
    };
  },
};
</script>

<style></style>
